package com.nyw.wanandroid.module.me.mvp;

import com.bakerj.rxretrohttp.RxRetroHttp;
import com.nyw.domain.common.api.WanApiResult;
import com.nyw.domain.common.loadmore.PageLoadMoreResponse;
import com.nyw.domain.domain.bean.request.home.HomeReq;
import com.nyw.domain.domain.bean.response.home.ArticleBean;
import com.nyw.domain.domain.bean.response.home.BannerBean;
import com.nyw.domain.domain.bean.response.home.CollectionBean;
import com.nyw.domain.domain.event.home.CollectionEvent;
import com.nyw.libproject.common.api.CBApiObserver;
import com.nyw.wanandroid.module.home.mvp.HomeContract;
import com.nyw.wanandroid.module.main.data.repository.mainRepositoryImpl;
import com.nyw.wanandroid.module.me.data.repository.ImineRepository;
import com.nyw.wanandroid.module.me.data.repository.mineRepositoryImpl;

import java.util.List;

import io.reactivex.Observable;

/**
 * @author nyw
 * @date 2019/07/10
 *
 * Generated by MVPGenerator
 */
public class MyCollectionPresenter extends MyCollectionContract.Presenter{
    private ImineRepository mRepository = new mineRepositoryImpl();

    public MyCollectionPresenter(MyCollectionContract.View view) {
        super(view);
    }

    @Override
    public void UnCollect(int id, int originId,int position) {
        RxRetroHttp.composeRequest(mRepository.Uncollect(id,originId), mView)
                .subscribe(new CBApiObserver<WanApiResult>() {
                    @Override
                    protected void success(WanApiResult data) {
                        ((MyCollectionContract.View) mView).UnCollectSuccese(position);
                        CollectionEvent.postUncollect(originId,id);
                    }
                });
    }

    @Override
    protected HomeReq getQuestBody() {
        HomeReq req = new HomeReq();
        return req;
    }

    @Override
    protected CollectionBean castDataToDest(CollectionBean collectionBean) {
        return collectionBean;
    }

    @Override
    protected Observable<List<CollectionBean>> getRefreshLoadObservable(HomeReq body) {
        return mRepository.getCollectArticle(body).map(PageLoadMoreResponse::getDatas);
    }

}

